<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>微服务管理系统</title>
		<!-- Tell the browser to be responsive to screen width -->
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<!-- Bootstrap 3.3.7 -->
		<link rel="stylesheet" href="../../bower_components/bootstrap/dist/css/bootstrap.min.css">
		<!-- Font Awesome -->
		<link rel="stylesheet" href="../../bower_components/font-awesome/css/font-awesome.min.css">
		<!-- Ionicons -->
		<link rel="stylesheet" href="../../bower_components/Ionicons/css/ionicons.min.css">
		<!-- DataTables -->
		<link rel="stylesheet" href="../../bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<!-- Theme style -->
		<link rel="stylesheet" href="../../dist/css/AdminLTE.min.css">
		<!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
		<link rel="stylesheet" href="../../dist/css/skins/_all-skins.min.css">

		<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

		<!-- Google Font -->
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
		<style>
			body,
			td {
				font-size: 15px !important;
			};
		</style>
	</head>

	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">

			<header class="main-header">
				<!-- Logo -->
				<a href="#" class="logo">
					<!-- mini logo for sidebar mini 50x50 pixels -->
					<span class="logo-mini"><b>微</b>服务</span>
					<!-- logo for regular state and mobile devices -->
					<span class="logo-lg"><b>微服务</b>管理系统</span>
				</a>
				<!-- Header Navbar: style can be found in header.less -->
				<nav class="navbar navbar-static-top">
					<!-- Sidebar toggle button-->
					<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
						<span class="sr-only">Toggle navigation</span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</a>

					<div class="navbar-custom-menu">
						<ul class="nav navbar-nav">
							<!-- User Account: style can be found in dropdown.less -->
							<li class="dropdown user user-menu">
								<a href="#" class="dropdown-toggle" data-toggle="dropdown">
									<img src="../../dist/img/user2-160x160.jpg" class="user-image" alt="User Image">
									<span class="hidden-xs">admin</span>
								</a>
							</li>
							<!-- Control Sidebar Toggle Button -->
						</ul>
					</div>
				</nav>
			</header>
			<!-- Left side column. contains the logo and sidebar -->
			<aside class="main-sidebar">
				<!-- sidebar: style can be found in sidebar.less -->
				<section class="sidebar">
					<!-- Sidebar user panel -->
					<div class="user-panel">
						<div class="pull-left image">
							<img src="../../dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
						</div>
						<div class="pull-left info">
							<p>admin</p>
							<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
						</div>
					</div>
					<!-- sidebar menu: : style can be found in sidebar.less -->
					<ul class="sidebar-menu" data-widget="tree">
						<li class="treeview active">
							<a href="#">
								<i class="fa fa-table"></i> <span>列表</span>
								<span class="pull-right-container">
				                  <i class="fa fa-angle-left pull-right"></i>
				                </span>
							</a>
							<ul class="treeview-menu">
								<li><a href="list_page.html"><i class="fa fa-circle-o"></i>内部服务列表页</a></li>
								<li>
									<a href="outside_list_page.html"><i class="fa fa-circle-o"></i>外部服务列表页</a>
								</li>
							
								<li>
									<a href="dock_party_page.html"><i class="fa fa-circle-o"></i>接入方列表</a>
								</li>
								<li>
									<a href="user_authority.html"><i class="fa fa-circle-o"></i>用户权限管理</a>
								</li>
							</ul>
						</li>
						<li class="treeview active">
							<a href="#">
								<i class="fa fa-edit"></i> <span>表单</span>
								<span class="pull-right-container">
				                  <i class="fa fa-angle-left pull-right"></i>
				                </span>
							</a>
							<ul class="treeview-menu">
								<li>
									<a href="test_service.html"><i class="fa fa-tumblr"></i>内部服务测试</a>
								</li>
							</ul>
						</li>
					</ul>
				</section>
				<!-- /.sidebar -->
			</aside>

			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				<!-- Content Header (Page header) -->
				<section class="content-header">
					<h1>微服务管理系统</h1>
					<ol class="breadcrumb">
						<li><i class="fa fa-dashboard"></i> 主页</ a>
						</li>
						<li>外部服务</li>
						<li class="active">外部服务列表</li>
					</ol>
				</section>

				<!-- Main content -->
				<section class="content">
					<div class="row">
						<div class="col-xs-12">
							<div class="box">
								<div class="box-header">
									<div class="col-sm-6">
										<h3 class="box-title">外部服务列表</h3>
									</div>
			                        <div class="col-sm-4">
			                                <label for="apiNameForSearch" style="padding-top: 6px;float: left;margin-right: 5px;">服务名称&nbsp;</label>
			                                <div class="input-group input-group-sm" style="width: 220px;">
			                                    <input type="text"  class="form-control pull-right" name="apiNameForSearch" id="apiNameForSearch" onkeypress="return huichesearchApi()">
			                                    <div class="input-group-btn">
			                                        <button type="button" class="btn btn-default" id="apiNameSearch"  style="float: left;" onclick="searchInfoApi();"><i class="fa fa-search"></i></button>
			                                    </div>
			                                </div>
			                        </div>
									<button type="button" class="btn btn-danger" style="float: right; margin-right: 2%;" onclick="delOutServer();">
                      					<i class="fa fa-fw fa-times-circle"></i>删除
                  					</button>
									<button type="button" class="btn btn-default" style="float: right; margin-right: 2%;" onclick="addOutServerList();">
							             <i class="fa fa-fw fa-plus-circle"></i>新增
							         </button>
								</div>
								<!-- /.box-header -->
								<div class="box-body">
									<table id="outSerTab" class="table table-bordered table-striped" width="100%">
										<thead>
											<tr>
												<th style="text-align: center;">
												</th>
												<th style="text-align: center;">序号</th>
												<th style="text-align: center;">外部服务</th>
												<th style="text-align: center;">内部服务</th>
												<th style="text-align: center;">作者</th>
												<th style="text-align: center;">备注</th>
												<th style="text-align: center;">创建时间</th>
												<th style="text-align: center;">操作</th>
											</tr>
										</thead>
										<tbody></tbody>
									</table>
								</div>
								<!-- /.box-body -->
							</div>
							<!-- /.box -->
						</div>
						<!-- /.col -->
					</div>
					<!-- /.row -->
				</section>
				<!-- /.content -->
			</div>
		</div>
		<!-- ./wrapper -->
		<!-- 新增模态框（Modal） -->
		<div class="modal fade" id="serverListOutAddModal" tabindex="-1" role="dialog" aria-labelledby="addAcctSubjectModalLabel" aria-hidden="true">
			<!--<div class="modal-dialog modal-lg">-->
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<div class="row">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-right: 10px;">
									&times;
								</button>
							<h3 class="modal-title" style="text-align: center;margin-left: 22px;">编辑服务</h3>
						</div>
					</div>
					<div class="modal-body">
						<input type="hidden" class="form-control" name="flag" id="flag">
						<form id="out_addServer" class="form-horizontal">
							<div class="box-body">
								<label for="apiName" class="col-sm-3 control-label">外部服务</label>
								<div class="form-group">
									<div class="col-sm-7">
										<input type="text" class="form-control" name="apiName" id="apiName" minlength="5">
									</div>
								</div>
								<label for="serviceName" class="col-sm-3 control-label">内部服务</label>
								<div class="form-group">
									<div class="col-sm-7">
										<!--<input type="text" class="form-control" name="serviceName" id="serviceName">-->
										<select type="text" class="form-control" name="serviceName" id="serviceName"></select>
									</div>
								</div>
								<label for="author" class="col-sm-3 control-label">作者</label>
								<div class="form-group">
									<div class="col-sm-7">
										<input type="text" class="form-control" name="author" id="author">
									</div>
								</div>
								<label for="remark" class="col-sm-3 control-label">备注</label>
								<div class="form-group">
									<div class="col-sm-7">
										<input type="text" class="form-control" name="remark" id="remark">
									</div>
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary" onclick="saveOutServer();">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal dialog-->
		</div>
		<!-- /.Modal -->
		<!-- jQuery 3 -->
		<script src="../../bower_components/jquery/dist/jquery.min.js"></script>
		<!-- Bootstrap 3.3.7 -->
		<script src="../../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<!-- DataTables -->
		<script src="../../bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="../../bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
		<!-- SlimScroll -->
		<script src="../../bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
		<!-- FastClick -->
		<script src="../../bower_components/fastclick/lib/fastclick.js"></script>
		<!-- AdminLTE App -->
		<script src="../../dist/js/adminlte.min.js"></script>
		<!-- AdminLTE for demo purposes -->
		<script src="../../dist/js/demo.js"></script>
		<script src="common.js"></script>
		<!-- page script -->
		<script>
			var DataTablePaging = {
				language: { // 汉化
					zh_cn: {
						"sProcessing": "正在加载数据...",
						// "sLoadingRecords": "载入中...",
						"sLengthMenu": "显示&nbsp;_MENU_&nbsp;条 ",
						"sZeroRecords": "没有您要搜索的内容",
						"sInfo": "从_START_ 到 _END_ 条&nbsp;&nbsp;&nbsp;&nbsp;共 _TOTAL_ 条",
						"sInfoEmpty": "记录数为0",
						"sInfoFiltered": "(全部记录数 _MAX_  条)",
						"sInfoPostFix": "",
						"sSearch": "搜索",
						"sUrl": "",
						"oPaginate": {
							"sFirst": "第一页",
							"sPrevious": " 上一页 ",
							"sNext": " 下一页 ",
							"sLast": " 最后一页 "
						}
					}
				}
			};
			$(function() {
				$('#outSerTab').DataTable({
					"oLanguage": DataTablePaging.language.zh_cn,
					'paging': true,
					'lengthChange': false,
					'searching': false,
					'info': true,
					'width': '100%',
					//'autoWidth': true,
					"scrollY": "calc(80vh - 110px)", //表格内容部分高度设置为窗口高度-100px
					"scrollCollapse": true,
					"scrollX": false, //横向滚动条
					//"ordering": false,
					/*****/
					"fixedHeader": true,
					"responsive": true,
					//"iDisplayLength": 100,// 每页显示行数
					"columnDefs":[{
					　　　　'targets' : [0,1,3,4,5,7],    //除第2外，都默认不排序
					　　　　'orderable' : false
					　　}],
					'ajax': {
						"url": apiUrl,
						"type": "POST",
						"contentType": "application/json;charset=utf-8",
						"dataType": "json",
						"data": function(d) {
							d.Head = {
								"ApiName": "getApiServiceList",
								"Model": "debug"
							};
							d.Body = {
								"aName":$("#apiNameForSearch").val()
							};
							return JSON.stringify(d)
						},
						"dataSrc":"Body",
					},
					"columns": [{
							"data": "apiName",
							'width': "5%",
							'class': 'text-center',
							"render": function(data, type, full) {
								var i = '<div class="radio"><label><input type="radio" name="apiName" value="' + data + '"></label></div>';
								return i;
							}
						},
						{
							"data": "",
							'width': "7%",
							'class': 'text-center',
							"render": function(data, type, full, meta) {
								return meta.settings._iDisplayStart + meta.row + 1;
							}
						},
						{
							"data": "apiName",
							'width': "12.5%",
							'class': 'text-center',
						},
						{
							"data": "serviceName",
							'width': "13%",
							'class': 'text-center',
						},
						
						{
							"data": "author",
							'width': "12.5%",
							'class': 'text-center',
						},
						{
							"data": "remark",
							'width': "12.5%",
							'class': 'text-center',
						},
						{
							"data": "createTime",
							'width': "12.5%",
							'class': 'text-center',
						},
						
						{
							"data": "",
							'width': "12.5%",
							'class': 'text-center',
							"mRender": function(data, type, full) {
								// 启用
								return "<a href=\"javascript:void(0);\" style=\"cursor: pointer;color:#333\" class=\"label label-primary\" onclick=\"addOutServerList('" + full.apiName + "');\">配置</a>";
							}
						}
					],
					/*******/
				})
			});

		    // 进入页面初始化内服服务下拉框
		    function fn_initServiceName() {
		        $.ajax({
		            url: apiUrl,
					type: "POST",
					contentType: "application/json;charset=utf-8",
					dataType: "json",
					data: JSON.stringify(
							{
							    "Head": {
							        "ApiName": "getServiceList",
							        "Model":"debug"
							    },
							}),
					dataSrc:"Body",
		            success: function (result) {
		                $.each(result.Body, function (index, item) {
		                    var optDom=$('<option></option>');
		                    optDom.val(item.name);
		                    optDom.html(item.name);
		                    $("#serviceName").append(optDom);
		                });
		            },
		            error: function (msg) {
		            	alert("系统繁忙，请稍后重试");
		            }
		        });
		    };
		    

			function addOutServerList(name) {
				fn_initServiceName();
				if(name != null && name != undefined && name != ''){
					// 配置操作-请求后台数据并打开配置模态框
					// 设置弹框标识
					$("#flag").val("true");
					$("#apiName").attr("readonly","readonly");
					 $.ajax({
				        "url": apiUrl,
						"type": "POST",
						"contentType": "application/json;charset=utf-8",
				        "async" : true,
				        "data": JSON.stringify(
							{
							    "Head": {
							        "ApiName": "getApiServiceByName",
							        "Model":"debug"
							    },
							    "Body":{
							     "apiName":name
							    }
							}),
				        // 成功后开启模态框
				        success : showModal,
				        error : function() {
				            alert("系统繁忙，请稍后重试");
				        },
				        dataType : "json"
				    });
				}else{
					// 新增操作-打开模态框
					$("#flag").val("");
					$("#apiName").attr("readonly",false);
					$("#serverListOutAddModal").modal({
						backdrop: false, // 点击空白不关闭
						keyboard: false, // 按键盘esc不关闭
					});
				}
				
			};
			// 关闭模态框
			$("#serverListOutAddModal").on("hidden.bs.modal", function() {
				$(this).removeData("bs.modal");
				
				document.getElementById("out_addServer").reset();
				//$(this).find(".modal-content").children().remove();
			});
			
			// 查询成功后向模态框插入数据并开启模态框。data是返回的JSON对象
			function showModal(data){
				$("#apiName").val(data.Body.apiName);
				$("#serviceName").val(data.Body.serviceName);
			    $("#desc").val(data.Body.desc);
			    $("#remark").val(data.Body.remark);
			    $("#author").val(data.Body.author);
			    // 显示模态框
    			//$('#serverListOutAddModal').modal('show');
    			// 打开模态框
				$("#serverListOutAddModal").modal({
					backdrop: false, // 点击空白不关闭
					keyboard: false, // 按键盘esc不关闭
				});
			};
			
			// 保存 & 修改 服务信息
			function saveOutServer(){
				flag = $("#flag").val();
				if(flag != null && flag != undefined && flag != '' && flag == 'true'){
					// 配置操作提交
					var jsonData = getFormData();
					$.ajax({
				        "url": apiUrl,
						"type": "POST",
						"contentType": "application/json;charset=utf-8",
				        "async" : true,
				        "data": JSON.stringify(
							{
							    "Head": {
							        "ApiName": "updateApiService",
							        "Model":"debug"
							    },
							    "Body":jsonData
							}),
				        // 成功后开启模态框
				        success : function(d){
				        	var status = d.Head.Status;
				        	if(status != null && status != undefined && status != '' && status == '0'){
				        		// 添加成功-关闭模态框&刷新页面
				        		$("#serverListAddModal").on("hidden.bs.modal", function() {
								$(this).removeData("bs.modal");
								document.getElementById("addServer").reset();
								});
				        		window.location.reload();
				        	}else{
				        		// 添加失败，弹框提示
				        		alert(d.Head.Exception[0].desc)
				        	}
				        },
				        error : function() {
				            alert("系统繁忙，请稍后重试");
				        },
				        dataType : "json"
				    });
				}else{
					// 新增操作提交
					var jsonData = getFormData();
					$.ajax({
				        "url": apiUrl,
						"type": "POST",
						"contentType": "application/json;charset=utf-8",
				        "async" : true,
				        "data": JSON.stringify(
							{
							    "Head": {
							        "ApiName": "newApiService",
							        "Model":"debug"
							    },
							    "Body":jsonData
							}),
				        // 成功后开启模态框
				        success : function(d){
				        	var status = d.Head.Status;
				        	if(status != null && status != undefined && status != '' && status == '0'){
				        		// 添加成功-关闭模态框&刷新页面
				        		$("#serverListOutAddModal").on("hidden.bs.modal", function() {
								$(this).removeData("bs.modal");
								document.getElementById("out_addServer").reset();
								});
				        		window.location.reload();
				        	}else{
				        		// 添加失败，弹框提示
				        		alert(d.Head.Exception[0].desc)
				        	}
				        },
				        error : function() {
				            alert("系统繁忙，请稍后重试");
				        },
				        dataType : "json"
				    });
					
				}
			};
			
			//取容器内所有 input 组装成 json
			function getFormData(sel){
				json = {};
				$("#out_addServer input,#out_addServer textarea,#out_addServer select").each(function(){
					json[$(this).attr("name")] = $(this).val();
				});
				json["serviceStatus"] = $("input[name='serviceStatus']:checked").val()
				return json;
			};
			
			// 选中一行即为选中
			$('#outSerTab tbody').on('click', 'tr', function () {
		        $(this).find("td").find("input:radio").prop('checked', 'checked');
		    });
		    
		    function delOutServer(){
		    	// 获取选中的服务名称
				var apiName = $('input:radio[name="apiName"]:checked').val();
		        if(apiName == null || apiName == '' || apiName == undefined ){
		            alert("请选择一条数据");
		        }else{
		        	// 删除
		            if(window.confirm('你确定要删除服务吗？')){
	                 	$.ajax({
				        "url": apiUrl,
						"type": "POST",
						"contentType": "application/json;charset=utf-8",
				        "async" : true,
				        "data": JSON.stringify(
							{
							    "Head": {
							        "ApiName": "delApiService",
							        "Model":"debug"
							    },
							    "Body":{apiName:apiName}
							}),
					        // 成功后开启模态框
					        success : function(d){
					        	var status = d.Head.Status;
					        	if(status != null && status != undefined && status != '' && status == '0'){
					        		// 删除成功-刷新页面
					        		window.location.reload();
					        	}else{
					        		// 删除失败，弹框提示
					        		alert(d.Head.Exception[0].desc)
					        	}
					        },
					        error : function() {
					            alert("系统繁忙，请稍后重试");
					        },
					        dataType : "json"
					    });
		              }else{
		                 return false;
		             }
		        }
		    };
		    
		    function searchInfoApi() {
		        $("#outSerTab").DataTable().ajax.reload();
		    };
		    
		    function huichesearchApi(){//回车搜索
		        var keyCode =event.keyCode;
		        if(keyCode== 13){
		            searchInfoApi();
		            return false;
		        }
		    };
		</script>
	</body>

</html>